package com.itheima.web.controller.pms;

import com.itheima.result.ResultData;
import com.itheima.service.pms.PmsProductAttributeService;
import com.itheima.vo.pms.ProductAttributeParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productAttribute")
@Slf4j
public class PmsProductAttributeController {
    @DubboReference
    private PmsProductAttributeService pmsProductAttributeService;

    /**
     * 根据商品分类的id获取商品属性及属性分类
     * @param productCategoryId
     * @return
     */
    @GetMapping("/attrInfo/{productCategoryId}")
    public ResultData attrInfo(@PathVariable Long productCategoryId) {
        return pmsProductAttributeService.attrInfo(productCategoryId);
    }

    /**
     * 添加商品属性信息
     * @param productAttributeParam
     * @return
     */
    @PostMapping("create")
    public ResultData create(@RequestBody ProductAttributeParam productAttributeParam) {
        pmsProductAttributeService.create(productAttributeParam);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 批量删除商品属性
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public ResultData delete(@RequestParam List<Long> ids) {
        pmsProductAttributeService.delete(ids);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 根据分类查询属性列表或参数列表
     * @param cid
     * @param type
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list/{cid}")
    public ResultData listAttribute(@PathVariable Long cid , @RequestParam Integer type ,Long  pageNum ,Long pageSize) {
        return pmsProductAttributeService.listAttribute(cid , type , pageNum , pageSize);
    }

    /**
     * 修改商品属性信息
     * @param id
     * @param productAttributeParam
     * @return
     */
    @PostMapping("/update/{id}")
    public ResultData updateAttribute(@PathVariable Long id , @RequestBody ProductAttributeParam productAttributeParam) {
        pmsProductAttributeService.updateAttribute(id , productAttributeParam);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 查询单个商品属性
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultData getAttribute(@PathVariable Long id) {
        return ResultData.ok("操作成功" , pmsProductAttributeService.getAttribute(id));
    }
}
